package com.wsj.a.collapsingdemo.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.wsj.a.collapsingdemo.R;

import java.util.List;

/**
 * Created by linxiujie on 2018/8/6.
 * TODO:公告滚动栏
 */

public class MyViewFlipper extends ViewFlipper {
    //字体颜色
    private int mTextColor;
    //字体大小
    private float mTextSize;

    public MyViewFlipper(Context context) {
        super(context);
    }

    public MyViewFlipper(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyViewFlipper);
        mTextColor = typedArray.getColor(R.styleable.MyViewFlipper_frontColor, Color.BLACK);
        mTextSize = typedArray.getDimension(R.styleable.MyViewFlipper_frontSize,14);
    }

    //填充数据
    public void setData(List<String> data){
        for(int i = 0; i < data.size(); i++ ){
            TextView item = new TextView(getContext());
            item.setText(data.get(i));
            item.setTextColor(mTextColor);
            item.setTextSize(mTextSize);
            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            item.setLayoutParams(layoutParams);
            item.setGravity(Gravity.CENTER_VERTICAL);
            //添加到当前的控件中
            addView(item);
        }
    }
}
